import { MiddlewareConsumer, Module, NestModule, RequestMethod, Post } from '@nestjs/common';
import { CoreModule } from './core/core.module';
import { Book1Module } from './book1/book1.module';
import { AlbumModule } from './album/album.module';
import { ProductModule } from './product/product.module';
import { CartModule } from './cart/cart.module';
import { LoggerMiddleware } from './core/middleware/logger.middleware';
import { UserController } from './core/controller/user.controller';
import cors from'cors';
import { TimestampMiddleware } from './core/middleware/timestamp.middleware';
import { UsersService } from './core/service/users.service';
import { UsersController } from './core/controller/users.controller';
import { RequestTimeMiddleware } from './core/middleware/resquest-time.middleware';
import { GoodController } from './core/controller/good.controller';
import { WorkController } from './core/controller/work.controller';
import { WorkService } from './core/service/work.service';
import { APP_FILTER } from '@nestjs/core';
import { HttpExceptionFilter } from './core/filter/HttpExceptionFilter';
@Module({
  imports: [CoreModule, Book1Module, AlbumModule, CartModule, ProductModule],
  controllers: [UsersController, UserController, WorkController],
  providers: [
    UsersService,
    WorkService, // 👈 加上这个
    {
      provide: APP_FILTER,
      useClass: HttpExceptionFilter,
    },
  ],
})
// export class AppModule implements NestModule{
//    configure(consumer: MiddlewareConsumer) {
//     consumer
//       .apply(TimestampMiddleware)
//       .forRoutes('*'); // 对所有路由生效
//   }
//   export class AppModule {
//   configure(consumer: MiddlewareConsumer) {
//     consumer
//       .apply(RequestTimeMiddleware)
//       .forRoutes(GoodController); // 仅对 GoodController 生效
//   }
// }
  // configure(consumer: MiddlewareConsumer) {
  //   //要通配user目录下所有以及get请求
  //   consumer.apply(LoggerMiddleware,cors,TimestampMiddleware).forRoutes(UserController,UsersController);//当前路由
  //   //npm install @types/cors
  // }
export class AppModule {
  configure(consumer: MiddlewareConsumer) {
    consumer
      .apply(RequestTimeMiddleware)
      .forRoutes(GoodController);
  }
}
  

